package com.sxg.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sxg.convert.SxgShopConcernConvert;
import com.sxg.dao.SxgShopConcernDao;
import com.sxg.entity.SxgShopConcernEntity;
import com.sxg.query.SxgShopConcernQuery;
import com.sxg.service.SxgShopConcernService;
import com.sxg.vo.SxgShopConcernVO;
import lombok.AllArgsConstructor;
import com.sxg.page.PageResult;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 店铺收藏表
 *
 * @author 浪漫写尽歌谱 3298751420@qq.com
 * @since 1.0.0 2024-03-07
 */
@Service
@AllArgsConstructor
public class SxgShopConcernServiceImpl extends ServiceImpl<SxgShopConcernDao, SxgShopConcernEntity> implements SxgShopConcernService {

    @Override
    public PageResult<SxgShopConcernVO> page(SxgShopConcernQuery query) {
        IPage<SxgShopConcernEntity> page = baseMapper.selectPage(PageResult.getPage(query), getWrapper(query));

        return new PageResult<>(SxgShopConcernConvert.INSTANCE.convertList(page.getRecords()), page.getTotal());
    }

    private LambdaQueryWrapper<SxgShopConcernEntity> getWrapper(SxgShopConcernQuery query){
        LambdaQueryWrapper<SxgShopConcernEntity> wrapper = Wrappers.lambdaQuery();
        return wrapper;
    }

    @Override
    public void save(SxgShopConcernVO vo) {
        SxgShopConcernEntity entity = SxgShopConcernConvert.INSTANCE.convert(vo);

        baseMapper.insert(entity);
    }

    @Override
    public void update(SxgShopConcernVO vo) {
        SxgShopConcernEntity entity = SxgShopConcernConvert.INSTANCE.convert(vo);

        updateById(entity);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void delete(List<Long> idList) {
        removeByIds(idList);
    }

}